<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>迁徙之途|Migration.Ac.Cn</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.css?v=4.7.0" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="/summernote/summernote.css" rel="stylesheet">
    <link href="/summernote/summernote-bs4.css" rel="stylesheet">
    <link href="/summernote/plugin/emoji/summernote-ext-emoji-ajax.css" rel="stylesheet">
    
    <!-- 全局js -->
    <script src="/js/jquery.min.js?v=2.1.4"></script>
    <script src="/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="/js/layer/layer.js"></script>

    <!-- 自定义js -->
    <script src="/js/content.js?v=1.0.0"></script>

    <!-- SUMMERNOTE -->
    <script src="/summernote/summernote.js"></script>
    <script src="/summernote/lang/summernote-zh-CN.js"></script>
    <script src="/summernote/plugin/emoji/summernote-ext-emoji-ajax.js"></script>
    
    <!-- layerDate plugin javascript -->
    <script src="/js/plugins/layer/laydate/laydate.js"></script>
    
<style>
	.hidden_button {
		visibility: hidden;
	}
	.media-body:hover .hidden_button {
		visibility: visible;
	}
    	
	.cmt-more-wrap-gw {
		text-align: center;
		font-size: 12px;
		height: 30px;
		line-height: 30px;
		color: #999;
		background: #f0f0f0;
		cursor: pointer;
	}
	.cmt-more-wrap-gw:hover {
	    /*background: #a7b1c2!important;*/
	    color: #5CBFB1!important;
	}
	
</style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <table width="100%" style="border-collapse: collapse;">
                        	<tr>
                        		<td colspan="2" align="left">
	                            	<div class="input-group" style="width: 100%;">
										<label style="font-size: 16px;">标题：</label>
										<label id="title_label_id" style="font-size: 16px; align: left"></label>
										<input id="title_id" type="text" class="sr-only" value=""/>
									</div>
	                            </td>
	                            <td width="40%" colspan="2" align="left">
	                            	<div class="input-group" style="width: 100%;">
										<label style="font-size: 16px;">标签：</label>
										<label id="labels_label_id" style="font-size: 16px; align: left"></label>
										<input id="labels_id" type="text" class="sr-only" value=""/>
									</div>
	                            </td>
	                            <td width="20%" align="center">
			                        <button id="edit_id" class="btn btn-primary btn-xs" onclick="edit()" type="button" style="padding: 6px 6px; width: 80%;">编&nbsp;&nbsp;&nbsp;&nbsp;辑</button>
	                            </td>
	                        </tr>
	                        <tr>
	                            <td width="20%" align="left">
	                            	<div class="input-group">
										<label style="font-size: 16px;">作者：</label>
										<label id="author_label_id" style="font-size: 16px; align: left"></label>
										<input id="author_id" type="text" class="sr-only" value=""/>
									</div>
	                            </td>
	                            <td width="20%" align="left">
	                            	<div class="input-group">
										<label style="font-size: 16px;">时间：</label>
										<label id="publishTime_label_id" style="font-size: 16px; align: left"></label>
										<input id="publishTime_id" type="text" class="sr-only" value="" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"/>
									</div>
	                            </td>
	                            <td width="20%" align="left">
	                            	<div class="input-group">
										<label style="font-size: 16px;">分类：</label>
										<label id="cname_label_id" style="font-size: 16px; align: left"></label>
										<select id="cname_id" class="sr-only" name="account">
											
	                                    </select>
	                            	</div>
	                            </td>
	                            <td width="20%" align="left">
	                            	<div class="input-group">
										<label style="font-size: 16px;">来源：</label>
										<label id="fromWhere_label_id" style="font-size: 16px; align: left"></label>
	                                    <select id="fromWhere_id" class="sr-only" name="account">
	                                        <option value="原创">原创</option>
	                                        <option value="摘抄">摘抄</option>
	                                        <option value="转载">转载</option>
	                                    </select>
	                            	</div>
	                            </td>
	                            <td width="20%" align="center">
			                        <button id="update_id" class="btn btn-primary btn-xs" onclick="window.history.go(-1);" type="button" style="padding: 6px 6px; width: 80%; height: 100%;">返&nbsp;&nbsp;&nbsp;&nbsp;回</button>
		                        </td>
	                        </tr>
                        </table>

                    </div>
                    <div id="eg" class="ibox-content">

                        <div id="summernote" class="wrapper">
                        	
                        </div><br><hr />
                        
                        <div class="row">
                        	<!--<h2>留下一条评论吧 :</h2>-->
                        	<div id="summernote_comment"></div><br>
							<div id="comments_id" class="col-lg-12">
								<!--<h4><a>最新</a>&nbsp;&nbsp;<a>最热</a></h4>-->
								<!--<div class="social-feed-box">
									<div class="social-avatar">
										<a class="pull-left">
											<img alt="image" src="http://www.lophan.com/logo.jpg">
										</a>
										<div class="media-body">
											<a>追光者</a>
											<small class="text-muted">2018-03-14 10:30:21</small>
										</div>
									</div>
								</div>-->
							</div>
						</div>
						<div>
						    <div id="get_more_comments_id" class="cmt-more-wrap-gw" onclick="getMoreComments();">查看更多&nbsp;<i class='fa fa-arrow-down'></i></div>
						</div>
                    </div>
                </div>
            </div>
        </div>
    </div>

<script src="js/common.js"></script>

<script type="text/javascript">
//给分类下拉框赋值
$.ajax({
    type : "GET",
    url : "/article/getCategory",
    async : false,
    dataType:"json",
    success : function(result) {
    	var categories = result.data;
    	for(var i=0; i<categories.length; i++) {
    		$("#cname_id").append("<option value='"+categories[i].cname+"'>"+categories[i].cname+"</option>");
    	}
    }
});

var article_id;
var article_title;
var article_content;
var currentPage = 1;
var pageSize = 15;
$(document).ready(function () {
	//获取文章内容
	article_id=getUrlParam("article_id");
	$.ajax({
	    type : "GET",
	    url : "/article/getArticle/"+article_id,
	    async : false,
	    dataType:"json",
	    success : function(result) {
	    	if (result.code==0) {
		    	var article = result.data;
		    	
		    	article_content = article.content;
		    	$('#summernote').html(article_content);
		    	
		    	article_title = article.title;
		    	$("#title_label_id").html(article.title);
		    	$("#title_id").val(article.title);
		    	
		    	$("#labels_label_id").html(article.labels);
		    	$("#labels_id").val(article.labels);
		    	
		    	$("#author_label_id").html(article.author);
		    	$("#author_id").val(article.author);
		    	
		    	$("#publishTime_label_id").html(millisecondsToLocalDate(article.publishTime));
		    	$("#publishTime_id").val(millisecondsToLocalDate(article.publishTime));
		    	
		    	$("#cname_label_id").html(article.cname);
		    	$("#cname_id").prepend("<option value='"+article.cname+"' selected='selected'>"+article.cname+"</option>");
		    	
		    	$("#fromWhere_label_id").html(article.fromWhere);
		    	$("#fromWhere_id").prepend("<option value='"+article.fromWhere+"' selected='selected'>"+article.fromWhere+"</option>");
	    	} else {
            	parent.layer.msg('获取文章内容失败！', {
				    icon: 2,
					time:1000
				});
            }
	    }
	});
	

	//加载评论框编辑器
	createEditor('#summernote_comment');
	
	//加载评论
	$.ajax({
        type : "POST",
        url : "/comment/findByArticleIdAndStatus",
        async : true,
        data : {
        	"articleId" : article_id,
        	"status" : 1,
        	"currentPage" : currentPage,
        	"pageSize" : pageSize
        },
        dataType:"json",
        success : function(result) {
            if (result.code==0) {
				var comments = result.data.comments;
			　　 for(var key in comments){
					var date = new Date(parseInt(comments[key]['publishTime']));
					var dateStr = date.getFullYear()+'-'+date.getMonth()+'-'+date.getDay()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();
					$('#comments_id').append("<div id='"+comments[key]['id']+"' class='social-feed-box'><div class='social-avatar'> <a class='pull-left'><img alt='image' src='"+comments[key]['headImg']+"'> </a><div class='media-body'><a>"+comments[key]['nickname']+"&nbsp;:&nbsp;</a><font>"+comments[key]['content']+"</font><br><small class='text-muted'>"+dateStr+"<a class='hidden_button' onclick='replyComment(this);' ref-id='"+comments[key]['id']+"' comment-id='"+comments[key]['id']+"' reply-to='"+comments[key]['nickname']+"'>&nbsp;&nbsp;回复</a></small></div></div></div>");
					
					var subComments = comments[key]['subComments'];
					if(!jQuery.isEmptyObject(subComments)) {
						for(var key2 in subComments){
							var frontId = subComments[key2]['frontId'];
							var date = new Date(parseInt(subComments[key2]['publishTime']));
							var dateStr = date.getFullYear()+'-'+date.getMonth()+'-'+date.getDay()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();
							if(frontId == comments[key]['id']) {
								$('#'+comments[key]['id']).append("<div class='social-avatar' style='background: #F7F7F7; padding: 10px 15px 5px 55px;'> <a class='pull-left'><img alt='image' src='"+subComments[key2]['headImg']+"'> </a><div class='media-body'><a>"+subComments[key2]['nickname']+"</a>&nbsp;回复&nbsp;<a>"+comments[frontId]['nickname']+"&nbsp;:&nbsp;</a><font>"+subComments[key2]['content']+"</font><br><small class='text-muted'>"+dateStr+"<a class='hidden_button' onclick='replyComment(this);' ref-id='"+comments[key]['id']+"' comment-id='"+subComments[key2]['id']+"' reply-to='"+subComments[key2]['nickname']+"'>&nbsp;&nbsp;回复</a></small></div></div>");
							} else {
								$('#'+comments[key]['id']).append("<div class='social-avatar' style='background: #F7F7F7; padding: 10px 15px 5px 55px;'> <a class='pull-left'><img alt='image' src='"+subComments[key2]['headImg']+"'> </a><div class='media-body'><a>"+subComments[key2]['nickname']+"</a>&nbsp;回复&nbsp;<a>"+subComments[frontId]['nickname']+"&nbsp;:&nbsp;</a><font>"+subComments[key2]['content']+"</font><br><small class='text-muted'>"+dateStr+"<a class='hidden_button' onclick='replyComment(this);' ref-id='"+comments[key]['id']+"' comment-id='"+subComments[key2]['id']+"' reply-to='"+subComments[key2]['nickname']+"'>&nbsp;&nbsp;回复</a></small></div></div>");
							}
						}
					}
				}
				
				//移除更多评论按钮
				var _cp = result.data.currentPage;
				var _totalPages = result.data.totalPages;
				if(_cp == _totalPages) {
					$("#get_more_comments_id").remove();
				}
            } else {
            	parent.layer.msg('评论加载失败！', {
				    icon: 2,
					time:1000
				});
            }
        }
    });
});

function getMoreComments() {
	currentPage = currentPage + 1;
	//加载所有评论
	$.ajax({
        type : "POST",
        url : "/comment/findByArticleIdAndStatus",
        async : true,
        data : {
        	"articleId" : article_id,
        	"status" : 1,
        	"currentPage" : currentPage,
        	"pageSize" : pageSize
        },
        dataType:"json",
        success : function(result) {
            if (result.code==0) {
				var comments = result.data.comments;
//				console.log(result);
				for(var key in comments){
					var date = new Date(parseInt(comments[key]['publishTime']));
					var dateStr = date.getFullYear()+'-'+date.getMonth()+'-'+date.getDay()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();
					$('#comments_id').append("<div id='"+comments[key]['id']+"' class='social-feed-box'><div class='social-avatar'> <a class='pull-left'><img alt='image' src='"+comments[key]['headImg']+"'> </a><div class='media-body'><a>"+comments[key]['nickname']+"&nbsp;:&nbsp;</a><font>"+comments[key]['content']+"</font><br><small class='text-muted'>"+dateStr+"<a class='hidden_button' onclick='replyComment(this);' ref-id='"+comments[key]['id']+"' comment-id='"+comments[key]['id']+"' reply-to='"+comments[key]['nickname']+"'>&nbsp;&nbsp;回复</a></small></div></div></div>");
					
					var subComments = comments[key]['subComments'];
					if(!jQuery.isEmptyObject(subComments)) {
						for(var key2 in subComments){
							var frontId = subComments[key2]['frontId'];
							var date = new Date(parseInt(subComments[key2]['publishTime']));
							var dateStr = date.getFullYear()+'-'+date.getMonth()+'-'+date.getDay()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();
							if(frontId == comments[key]['id']) {
								$('#'+comments[key]['id']).append("<div class='social-avatar' style='background: #F7F7F7; padding: 10px 15px 5px 55px;'> <a class='pull-left'><img alt='image' src='"+subComments[key2]['headImg']+"'> </a><div class='media-body'><a>"+subComments[key2]['nickname']+"</a>&nbsp;回复&nbsp;<a>"+comments[frontId]['nickname']+"&nbsp;:&nbsp;</a><font>"+subComments[key2]['content']+"</font><br><small class='text-muted'>"+dateStr+"<a class='hidden_button' onclick='replyComment(this);' ref-id='"+comments[key]['id']+"' comment-id='"+subComments[key2]['id']+"' reply-to='"+subComments[key2]['nickname']+"'>&nbsp;&nbsp;回复</a></small></div></div>");
							} else {
								$('#'+comments[key]['id']).append("<div class='social-avatar' style='background: #F7F7F7; padding: 10px 15px 5px 55px;'> <a class='pull-left'><img alt='image' src='"+subComments[key2]['headImg']+"'> </a><div class='media-body'><a>"+subComments[key2]['nickname']+"</a>&nbsp;回复&nbsp;<a>"+subComments[frontId]['nickname']+"&nbsp;:&nbsp;</a><font>"+subComments[key2]['content']+"</font><br><small class='text-muted'>"+dateStr+"<a class='hidden_button' onclick='replyComment(this);' ref-id='"+comments[key]['id']+"' comment-id='"+subComments[key2]['id']+"' reply-to='"+subComments[key2]['nickname']+"'>&nbsp;&nbsp;回复</a></small></div></div>");
							}
						}
					}
				}
				
				//移除更多评论按钮
				var _cp = result.data.currentPage;
				var _totalPages = result.data.totalPages;
				if(_cp == _totalPages) {
					$("#get_more_comments_id").remove();
				}
            } else {
            	parent.layer.msg('评论加载失败！', {
				    icon: 2,
					time:1000
				});
            }
        }
    });
}

function createButton(summernoteId) {
	var ui = $.summernote.ui;
	var button = ui.button({
	    contents: '<i class="fa fa-send-o"></i>&nbsp;提交评论',
	    click: function () {
			adminSubmitComment(summernoteId);
	    }
	});
	return button.render();  // return button as jquery object
}


function createEditor(summernoteId) {
	$(summernoteId).summernote({
        lang : 'zh-CN',
        height : 100,   //set editable area's height
	    codemirror : { // codemirror options
	    	theme : 'monokai'
		},
		focus : true,
		buttons: {
		    submitbtn: createButton(summernoteId)
		},
		toolbar : [
		     	['font', ['color']],
		     	['fontstyle', ['italic', 'bold', 'underline']],
		     	['insert', ['emoji', 'picture', 'link']],
		     	['misc', ['undo', 'redo', 'help']],
		     	['mybuttons', ['submitbtn']]
		],
	    placeholder : '理性思考，文明评论...',
        callbacks : {
            onImageUpload: function (files) {
                uploadFile(summernoteId, files[0]);
            }
	    }
    });
}


function cancelReply(obj) {
	//销毁回复编辑器
	$("#summernote_reply_comment").summernote('destroy');
	$("#summernote_reply_comment").remove();
	$("#summernote_cancel_reply").remove();
}


function replyComment(obj) {
	//如果存在未关闭回复编辑器，先销毁
	$("#summernote_reply_comment").summernote('destroy');
	$("#summernote_reply_comment").remove();
	$("#summernote_cancel_reply").remove();
	
	$(obj).after("&nbsp;&nbsp;<a id='summernote_cancel_reply' onclick='cancelReply(this);'>取消回复</a><div id='summernote_reply_comment' ref-id=''></div>");
    $('#summernote_reply_comment').attr('ref-id',$(obj).attr('ref-id'));
    $('#summernote_reply_comment').attr('front-id',$(obj).attr('comment-id'));
	$('#summernote_reply_comment').attr('reply-to',$(obj).attr('reply-to'));
	createEditor('#summernote_reply_comment');
}


function submitComment(summernoteId) {
	//通过QQ/微信互联获取这两个参数
	var nicknames = new Array('AA','BB','CC','DD','EE');
	var headImgs = new Array('http://www.lophan.com/logo.jpg','http://www.lophan.com/boy.jpg','http://www.lophan.com/20180321111514-meinv.jpg','http://www.lophan.com/demo.jpg','http://www.lophan.com/demo2.jpg');
	var idx = Math.floor(Math.random()*(4-0+1)+0);
	var nickname=nicknames[idx];
	var headImg=headImgs[idx];
	//通过QQ/微信互联获取这两个参数

	var re0 = /&nbsp;/g; //&nbsp;类型空格
	var re1 = /(^\s*)|(\s*$)|( )/g; //其他类型空格
	var re2 = /<\/?((?!img).)*?\/?>/g; //去除img标签外其他所有html标签
	var content = $(summernoteId).summernote('code').replace(re2,'');
	if(content.replace(re0,'').replace(re1,'')=='') {
		//重置操作的话则必须销毁、重新生成，所以这里自定义函数clearEditArea，避免重置编辑器
		$(summernoteId).summernote('clearEditArea');
		$(summernoteId).summernote('focus');
		parent.layer.msg('评论内容不能为空！', {
			icon: 2,
			time:1000
		});
		return;
	} else {
		var originTime = new Date();
		var publishTime = convertDateToGivenFormat(originTime, "yyyy-MM-dd HH:mm:ss");
//		console.log(publishTime);
		var refId = $('#summernote_reply_comment').attr('ref-id');
		var frontId = $('#summernote_reply_comment').attr('front-id');
		var replyTo = $('#summernote_reply_comment').attr('reply-to');
		$.ajax({
			type : "POST",
			url : "/comment/submitComment",
			async : true,
			data : {
				"articleId" : article_id,
				"articleTitle" : article_title,
				"refId" : refId, //只有二级评论这个参数才有值
				"frontId" : frontId, //只有二级评论这个参数才有值
				"nickname" : nickname,
				"headImg" : headImg,
				"content" : content,
				"publishTime" : publishTime
			},
			dataType:"json",
			success : function(result) {
				if (result.code==0) {
					parent.layer.msg('提交成功！', {
						icon: 1,
						time:1000
					});

					if(summernoteId == '#summernote_comment') {
						//如果是一级评论框，重置操作的话则必须销毁、重新生成，所以这里自定义函数clearEditArea，避免重置编辑器
						$(summernoteId).summernote('clearEditArea');
					} else {
						//如果是二级评论框，直接销毁
						cancelReply(this);
					}
					var dateStr = originTime.getFullYear()+'-'+originTime.getMonth()+'-'+originTime.getDay()+' '+originTime.getHours()+':'+originTime.getMinutes()+':'+originTime.getSeconds();
					if(!jQuery.isEmptyObject(refId)) {
						$('#'+refId).append("<div class='social-avatar' style='background: #F7F7F7; padding: 10px 15px 5px 55px;'> <a class='pull-left'><img alt='image' src='"+headImg+"'> </a><div class='media-body'><a>"+nickname+"</a>&nbsp;回复&nbsp;<a>"+replyTo+"</a>&nbsp;:&nbsp;<font>"+content+"<font><br><small class='text-muted'>"+dateStr+"<a class='hidden_button' onclick='replyComment(this);' ref-id='"+refId+"' comment-id='"+result.data+"' reply-to='"+nickname+"'>&nbsp;&nbsp;<i class='fa fa-mail-reply fa-rotate-270'></i>&nbsp;回复</a></small></div>");
					} else {
						$('#comments_id').prepend("<div id='"+result.data+"' class='social-feed-box'><div class='social-avatar'> <a class='pull-left'><img alt='image' src='"+headImg+"'> </a><div class='media-body'><a>"+nickname+"&nbsp;:&nbsp;</a><font>"+content+"<font><br><small class='text-muted'>"+dateStr+"<a class='hidden_button' onclick='replyComment(this);' ref-id='"+result.data+"' comment-id='"+result.data+"' reply-to='"+nickname+"'>&nbsp;&nbsp;<i class='fa fa-mail-reply fa-rotate-270'></i>&nbsp;回复</a></small></div></div>");
					}
				} else {
					parent.layer.msg('提交失败！', {
						icon: 2,
						time:1000
					});
				}
			}
		});
	}
}


function adminSubmitComment(summernoteId) {
	var nickname = localStorage.getItem("nickname");
	var headImg = localStorage.getItem("headImg");

	var re0 = /&nbsp;/g; //&nbsp;类型空格
	var re1 = /(^\s*)|(\s*$)|( )/g; //其他类型空格
	var re2 = /<\/?((?!img).)*?\/?>/g; //去除img标签外其他所有html标签
	var content = $(summernoteId).summernote('code').replace(re2,'');
	if(content.replace(re0,'').replace(re1,'')=='') {
		//重置操作的话则必须销毁、重新生成，所以这里自定义函数clearEditArea，避免重置编辑器
		$(summernoteId).summernote('clearEditArea');
		$(summernoteId).summernote('focus');
		parent.layer.msg('评论内容不能为空！', {
			icon: 2,
			time:1000
		});
		return;
	} else {
		var originTime = new Date();
		var publishTime = convertDateToGivenFormat(originTime, "yyyy-MM-dd HH:mm:ss");
//		console.log(publishTime);
		var refId = $('#summernote_reply_comment').attr('ref-id');
		var frontId = $('#summernote_reply_comment').attr('front-id');
		var replyTo = $('#summernote_reply_comment').attr('reply-to');
		$.ajax({
			type : "POST",
			url : "/comment/adminSubmitComment",
			async : true,
			data : {
				"articleId" : article_id,
				"articleTitle" : article_title,
				"refId" : refId, //只有二级评论这个参数才有值
				"frontId" : frontId, //只有二级评论这个参数才有值
				"nickname" : nickname,
				"headImg" : headImg,
				"content" : content,
				"publishTime" : publishTime
			},
			dataType:"json",
			success : function(result) {
				if (result.code==0) {
					parent.layer.msg('提交成功！', {
						icon: 1,
						time:1000
					});

					if(summernoteId == '#summernote_comment') {
						//如果是一级评论框，重置操作的话则必须销毁、重新生成，所以这里自定义函数clearEditArea，避免重置编辑器
						$(summernoteId).summernote('clearEditArea');
					} else {
						//如果是二级评论框，直接销毁
						cancelReply(this);
					}
					var dateStr = originTime.getFullYear()+'-'+originTime.getMonth()+'-'+originTime.getDay()+' '+originTime.getHours()+':'+originTime.getMinutes()+':'+originTime.getSeconds();
					if(!jQuery.isEmptyObject(refId)) {
						$('#'+refId).append("<div class='social-avatar' style='background: #F7F7F7; padding: 10px 15px 5px 55px;'> <a class='pull-left'><img alt='image' src='"+headImg+"'> </a><div class='media-body'><a>"+nickname+"</a>&nbsp;回复&nbsp;<a>"+replyTo+"</a>&nbsp;:&nbsp;<font>"+content+"<font><br><small class='text-muted'>"+dateStr+"<a class='hidden_button' onclick='replyComment(this);' ref-id='"+refId+"' comment-id='"+result.data+"' reply-to='"+nickname+"'>&nbsp;&nbsp;<i class='fa fa-mail-reply fa-rotate-270'></i>&nbsp;回复</a></small></div>");
					} else {
						$('#comments_id').prepend("<div id='"+result.data+"' class='social-feed-box'><div class='social-avatar'> <a class='pull-left'><img alt='image' src='"+headImg+"'> </a><div class='media-body'><a>"+nickname+"&nbsp;:&nbsp;</a><font>"+content+"<font><br><small class='text-muted'>"+dateStr+"<a class='hidden_button' onclick='replyComment(this);' ref-id='"+result.data+"' comment-id='"+result.data+"' reply-to='"+nickname+"'>&nbsp;&nbsp;<i class='fa fa-mail-reply fa-rotate-270'></i>&nbsp;回复</a></small></div></div>");
					}
				} else {
					parent.layer.msg('提交失败！', {
						icon: 2,
						time:1000
					});
				}
			}
		});
	}
}

	
function edit() {
	//隐藏label框
	$("#title_label_id").attr("class", "sr-only");
    $("#labels_label_id").attr("class", "sr-only");
	$("#author_label_id").attr("class", "sr-only");
    $("#publishTime_label_id").attr("class", "sr-only");
    $("#cname_label_id").attr("class", "sr-only");
    $("#fromWhere_label_id").attr("class", "sr-only");
	//初始化输入框
	$("#title_id").val($("#title_label_id").html().trim());
    $("#labels_id").val($("#labels_label_id").html().trim());
    $("#author_id").val($("#author_label_id").html().trim());
    $("#publishTime_id").val($("#publishTime_label_id").html().trim());
    $("#cname_id").val($("#cname_label_id").html().trim());
    $("#fromWhere_id").val($("#fromWhere_label_id").html().trim());
    //显示输入框
	$("#title_id").attr("class", "form-control");
    $("#labels_id").attr("class", "form-control");
	$("#author_id").attr("class", "form-control");
	$("#publishTime_id").attr("class", "form-control");
    $("#cname_id").attr("class", "form-control");
    $("#fromWhere_id").attr("class", "form-control");
    
    $("#eg").addClass("no-padding");
    $('#summernote').summernote({
        lang: 'zh-CN',
        height: 490,   //set editable area's height
	    codemirror: { // codemirror options
	    	theme: 'monokai'
		},
		toolbar: [
		     	// [groupName, [list of button]]
		     	['style', ['style']],
		     	['font', ['fontname', 'fontsize', 'color']],
		     	['fontstyle', ['italic', 'bold', 'underline', 'height', 'clear']],
		     	['paragrah', ['ul', 'ol', 'strikethrough', 'superscript', 'subscript', 'paragraph']],
		     	['insert', ['picture', 'link', 'video', 'table', 'hr', 'emoji', 'codeview']],
		     	['misc', ['undo', 'redo', 'help', 'fullscreen']]
		  	],
        focus: true,
        //调用图片上传
        callbacks: {
            onImageUpload: function (files) {
                uploadFile('#summernote', files[0]);
            }
        }
    });
    
    $("#edit_id").attr("onclick", "cancelEdit()");
    $("#edit_id").html("取&nbsp;&nbsp;&nbsp;&nbsp;消");
    $("#update_id").attr("onclick", "update()");
    $("#update_id").html("保&nbsp;&nbsp;&nbsp;&nbsp;存");
}
    
    
function uploadFile(summernoteId, file) {
	// 构造Form表单
	var fromData = new FormData();
	fromData.append("file", file);
	$.ajax({
		data: fromData,
		type: "POST",
		url: "/common/fileUpload",
		cache: false,
		contentType: false, //这里千万不要设置，否则无法上传
		processData: false,
		success: function(result) {
			if(result.code == 0) {
				parent.layer.msg('上传成功！', {
				    icon: 1,
					time:1000
				});
				$(summernoteId).summernote('insertImage', result.data);
			} else {
            	parent.layer.msg('上传失败！', {
				    icon: 2,
					time:1000
				});
            }
		}
	});
}
    
    
function cancelEdit() {
	$("#title_id").attr("class", "sr-only");
    $("#labels_id").attr("class", "sr-only");
    $("#author_id").attr("class", "sr-only");
    $("#publishTime_id").attr("class", "sr-only");
    $("#cname_id").attr("class", "sr-only");
    $("#fromWhere_id").attr("class", "sr-only");
    $("#title_label_id").removeAttr("class");
    $("#labels_label_id").removeAttr("class");
    $("#author_label_id").removeAttr("class");
    $("#publishTime_label_id").removeAttr("class");
    $("#cname_label_id").removeAttr("class");
    $("#fromWhere_label_id").removeAttr("class");
	$("#eg").removeClass("no-padding");
	
	$('#summernote').summernote('destroy');
    $('#summernote').html(article_content);
	
	$("#edit_id").attr("onclick", "edit()");
    $("#edit_id").html("编&nbsp;&nbsp;&nbsp;&nbsp;辑");
    $("#update_id").attr("onclick", "window.history.go(-1);");
    $("#update_id").html("返&nbsp;&nbsp;&nbsp;&nbsp;回");
}


function checkNull() {
	var re1 = /(^\s*)|(\s*$)|( )/g; //空格正则表达式
	var re2 = /<[^>]+>/g; //html标签正则表达式
	var re3 = /&nbsp;/g; //&nbsp;正则表达式
	
	var title = $("#title_id").val();
	var labels = $("#labels_id").val();
	var author = $("#author_id").val();
	var publishTime = $("#publishTime_id").val();
	var cname = $("#cname_id").val();
	var fromWhere = $("#fromWhere_id").val();
	var content = $('#summernote').summernote('code');
	
	if(title.replace(re1,'')=='') {
		parent.layer.msg('标题不能为空！', {
		    icon: 2,
			time:1000
		});
		return false;
	}
	if(labels.replace(re1,'')=='') {
		parent.layer.msg('标签不能为空！', {
		    icon: 2,
			time:1000
		});
		return false;
	}
	if(author.replace(re1,'')=='') {
		parent.layer.msg('作者不能为空！', {
		    icon: 2,
			time:1000
		});
		return false;
	}
	if(publishTime.replace(re1,'')=='') {
		parent.layer.msg('时间不能为空！', {
		    icon: 2,
			time:1000
		});
		return false;
	}
	if(cname=='请选择...') {
		parent.layer.msg('分类不能为空！', {
		    icon: 2,
			time:1000
		});
		return false;
	}
	if(fromWhere=='请选择...') {
		parent.layer.msg('来源不能为空！', {
		    icon: 2,
			time:1000
		});
		return false;
	}
	if(content.replace(re1,'').replace(re2,'').replace(re3,'')=='') {
		parent.layer.msg('文章内容不能为空！', {
		    icon: 2,
			time:1000
		});
		return false;
	}
	return true;
}


function update() {
	if(checkNull() == true) {
        var content = $('#summernote').summernote('code');
        var urlStr = "/article/update";

        $.ajax({
            type : "POST",
            url : urlStr,
            async : false,
            data : { //使用Json格式进行透传
            	"id" : article_id,
                "title" : $('#title_id').val(),
                "labels" : $('#labels_id').val(),
                "author" : $('#author_id').val(),
                "publishTime" : $('#publishTime_id').val(),
                "cname" : $('#cname_id').val(),
                "fromWhere" : $('#fromWhere_id').val(),
                "content" : content
            },
            dataType:"json",
            success : function(result) {
                if (result.code==0) {
                	parent.layer.msg('保存成功！', {
					    icon: 1,
						time:1000
					});
					
					$("#title_id").attr("class", "sr-only");
			        $("#labels_id").attr("class", "sr-only");
			        $("#author_id").attr("class", "sr-only");
			        $("#publishTime_id").attr("class", "sr-only");
			        $("#cname_id").attr("class", "sr-only");
			        $("#fromWhere_id").attr("class", "sr-only");
			        $("#title_label_id").removeAttr("class");
			        $("#title_label_id").html($("#title_id").val());
			        $("#labels_label_id").removeAttr("class");
			        $("#labels_label_id").html($("#labels_id").val());
			        $("#author_label_id").removeAttr("class");
			        $("#author_label_id").html($("#author_id").val());
			        $("#publishTime_label_id").removeAttr("class");
			        $("#publishTime_label_id").html($("#publishTime_id").val());
			        $("#cname_label_id").removeAttr("class");
			        $("#cname_label_id").html($("#cname_id").val());
			        $("#fromWhere_label_id").removeAttr("class");
			        $("#fromWhere_label_id").html($("#fromWhere_id").val());
					$("#eg").removeClass("no-padding");
					
                    $('#summernote').summernote('destroy');
                    $('#summernote').html(content);
                    
                    $("#edit_id").attr("onclick", "edit()");
			        $("#edit_id").html("编&nbsp;&nbsp;&nbsp;&nbsp;辑");
			        $("#update_id").attr("onclick", "window.history.go(-1);");
			        $("#update_id").html("返&nbsp;&nbsp;&nbsp;&nbsp;回");
                } else {
                	parent.layer.msg('保存失败！', {
					    icon: 2,
						time:1000
					});
                }
            }
        });
    }
}
</script>

</body>
</html>
